package com.oms;

import org.hibernate.cfg.Configuration;
import org.hibernate.SessionFactory;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;
//import java.io.*;

public class HibernateUtil {
	
	 private static final SessionFactory sessionFactory;
	 
	    static {
	    	
	      try {
	    	  
	    	  Configuration configuration = new Configuration();
	    	  configuration.configure();
	    	  
	    	  ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().
	    			  applySettings(configuration.getProperties()).buildServiceRegistry();
	    	sessionFactory = configuration.buildSessionFactory(serviceRegistry);
	    	
	      } catch (ExceptionInInitializerError ex) {
	        System.err.println("Initial SessionFactory creation failed." + ex);
	        throw new ExceptionInInitializerError(ex);
	      }
	    }

	    public static SessionFactory getSessionFactory() {
	      return sessionFactory;
	    }
	}	
